package com.javaclimb.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.javaclimb.mappers.UserMapper;
import com.javaclimb.pojo.Tree;
import com.javaclimb.pojo.User;
import com.javaclimb.service.UserService;
import com.javaclimb.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User verifyPassword(String username, String password) {
        return userMapper.verifyPassword(username, password);
    }

    @Override
    public User getByUsername(String username) {
        return userMapper.getByUsername(username);
    }

    @Override
    public int inserUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public User selectUserOfId(String id) {
        return userMapper.selectByUserId(id);
    }

    @Override
    public Boolean update(User user) {
        return userMapper.updateUserInfo(user) > 0;
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, Integer userId, String username, Integer sex, Integer age) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
        //2.执行查询
        List<User> userList = userMapper.list(userId,username,sex,age);//传递条件查询参数
        Page<User> p = (Page<User>) userList;
        //3.封装bean对象
        PageBean pB = new PageBean(p.getTotal(), p.getResult());
        return pB;
    }

    @Override
    public void delete(List<Integer> ids) {
        userMapper.delete(ids);
    }

}